/**
 * 扑克类叫分
 */
var _ = require('../../FrameWork/we_underscore');
var EnumPkRoom = require('../Enum/EnumPkRoom');
var ClientDelegate = require('../../FrameWork/Delegate/ClientDelegate');
var ClientPkDelegateType = require('../Delegate/ClientPkDelegateType');
var UtilGameObject = require('./../../FrameWork/Utils/UtilGameObject');
var PkSound = require('./../PkSound');
module.exports = cc.Class({
    extends: ClientDelegate,
    properties: {
        posShows: [cc.Node], //UI
        prefabLb: {
            default: null,
            type: cc.Prefab,
            displayName: '文字预设'
        },
        prefabSprite: {
            default: null,
            type: cc.Prefab,
            displayName: 'UI图预设'
        }
    },
    onLoad() {
        this._super();
        this.addListerDelegate(ClientPkDelegateType.Clinet_callScorResult, this.doShowCallScore.bind(this));
        this.addListerDelegate(ClientPkDelegateType.Clinet_doubleResult, this.doShowDouble.bind(this));
        this.addListerDelegate(ClientPkDelegateType.Clinet_cleanAllShowUI, this.cleanAll.bind(this));
        this.addListerDelegate(ClientPkDelegateType.Clinet_show_no_out_ui, this.doShowNoOutUI.bind(this));

        this.iniTest();
        this.resetNet();
    },

    resetNet() {
        this.cleanAll();
    },

    /** _info:{ 
     * seatIdx:1
     * }*/
    doShowNoOutUI(_info) {
        var seatIdx = _info.seatIdx;
        var lbCtr = UtilGameObject.getCtrByPrefabs(this.prefabLb, this.posShows[seatIdx]);
        lbCtr.setContentSize(cc.size(300, 300));
        lbCtr.setFontSize(45);
        lbCtr.setText('不 出');
        lbCtr.setColor(new cc.Color(255, 255, 255, 255));
        lbCtr.setOutlineColor(new cc.Color(255, 255, 255, 255));
        lbCtr.setOutlineColor2(new cc.Color(0, 0, 0, 70));
        lbCtr.setOutlineWidth(1);
        lbCtr.setOutlineWidth2(5);
        this.ctrList.push(lbCtr);
    },
    /** _info:{ 
     * seatIdx:1,
     * score:x
     * sex:1
     * }*/
    doShowCallScore(_info) {
        var score = _info.score;
        var seatIdx = _info.seatIdx;
        var sex = _info.sex;
        PkSound.callScore(score, sex);
        var lbCtr = UtilGameObject.getCtrByPrefabs(this.prefabLb, this.posShows[seatIdx]);
        lbCtr.setContentSize(cc.size(300, 300));
        lbCtr.setFontSize(45);
        if (0 == score) {
            lbCtr.setText('不 叫');
        } else {
            lbCtr.setText(score.toString() + ' 分');
        }

        // var spCtr = UtilGameObject.getCtrByPrefabs(this.prefabSprite, this.posShows[seatIdx]);
        // spCtr.setScore(score);
        this.ctrList.push(lbCtr);
    },

    /** _info:{ 
     * seatIdx:1,
     * double:x
     * }*/
    doShowDouble(_info) {
        var double = _info.double;
        var seatIdx = _info.seatIdx;
        var sex = _info.sex;
        PkSound.double(double, sex);
        // var spCtr = UtilGameObject.getCtrByPrefabs(this.prefabSprite, this.posShows[seatIdx]);
        // spCtr.setDouble(double);
        var lbCtr = UtilGameObject.getCtrByPrefabs(this.prefabLb, this.posShows[seatIdx]);
        lbCtr.setContentSize(cc.size(300, 300));
        lbCtr.setFontSize(45);
        lbCtr.setText(1 == double ? "加 倍" : "不加倍");
        this.ctrList.push(lbCtr);
    },

    cleanAll() {
        if (this.ctrList) {
            _.each(this.ctrList, function(_ctr) {
                if (!!_ctr && !!_ctr.node) {
                    _ctr.node.destroy();
                }
            });
        }
        this.ctrList = [];
    },

    iniTest() {
        // UtilGameObject.createDemoBtn([
        //     ['头像', function() {
        //             this.showHeadAll();
        //         }.bind(this) 
        //     ],
        // ]);
        // this.showHeadAll();
    }
});